<template>
  <div class="app-container">
    <uc-table url="admin/inBox/getInBoxPage" name="盒子" ref="inBoxTable" pageable table-border :search-form="searchForm">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column prop="boxId" label="盒子id" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectId" label="项目id" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="variantsNum" label="变量数" align="left" :show-overflow-tooltip="true">


        </el-table-column>
        <el-table-column prop="status" label="状态" align="left" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{scope.row.status |dateStatus}}
          </template>
        </el-table-column>

        <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {removeInBox} from "@/api/box";
export default {

  components: {UcTable},
  data(){
    return{
      searchForm: {
        deleted:false,
        type:0,
      },
      deleteLoading:false
    }
  },
  methods:{
    handleSearch(){
      this.$refs.inBoxTable.getTableData(1)
    },
    handleAdd(){
      this.$router.push("/sysconfig/boxEdit/0")
    },
    handleEdit(val){
      this.$router.push("/sysconfig/boxEdit/"+val.id)
    },
    handleDelete(val){
      this.$confirm('您确定要执行删除'+val.id+'这个盒子吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
          .then(() => {
            this.deleteLoading = true
            removeInBox(val).then(res=>{
              this.deleteLoading = false
              this.$notify.success({
                title: '成功',
                message: "删除盒子成功"
              })
              this.handleSearch()
            }).catch(res=>{
              this.deleteLoading = false
              this.$notify.error({
                title: '失败',
                message: res.msg
              })
            })
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
    },

  }
}
</script>

<style scoped>

</style>